import Vue from 'vue'
import Vuex from 'vuex'
import config from '@/config/config.js'
Vue.use(Vuex)

console.log(config.environment.api)
const store = new Vuex.Store({
	state: {
		version: config.environment.version,
		app_id: 'market',//测试环境和线上环境
		domain: config.environment.domain,
		userinfo: {},
		API: config.environment.api,
		subject: '',
		loading: false,
		imgUrl: '',
	},
	getters: {
		api: state => {//通过方法访问
			return state.API
		},
		imgUrl: state => {
			return process.env.NODE_ENV == 'development' ? `/${config.environment.apiImg}` : `${window.location.origin}${config.environment.apiImg}`
		},
		getSubject: state => {//通过方法访问
			return state.subject
		},
	},
	mutations: {
		changeMarketPageName(state, data) {
			state.marketPageName = data;
		},
		setLoading: state => {
			state.loading = true
		},
		cancalLoading: state => {
			state.loading = false
		}
	}
})

export default store
